package com.tool.engine.export.engine;

import com.tool.engine.export.exception.ExportTaskException;
import com.tool.engine.export.output.DataOutputSource;
import com.tool.engine.export.output.DataOutputSourceFactory;
import com.tool.engine.export.processor.ExportTaskProcessor;
import com.tool.engine.export.task.Task;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService;

@Slf4j
public class DefaultExportTaskEngine extends AbstractExportTaskEngine {

    @Setter
    private ExecutorService threadPoolExecutor;

    @Resource
    private Map<String, ExportTaskProcessor> processors;

    @Setter
    @Getter
    private String filePath;

    @Override
    public void addTask(Task<?> task, String processorName, String outPutType, Object... params) throws ExportTaskException {
        ExportTaskProcessor processor = processors.get(processorName);
        if (Objects.isNull(processor)) {
            log.warn("processor:{} not found", processorName);
            return;
        }
        DataOutputSource dataOutPutSource = DataOutputSourceFactory.createDataOutPutSource(outPutType, task, filePath);
        if (Objects.isNull(dataOutPutSource)) {
            log.warn("dataOutPutSource:{} not found", outPutType);
            return;
        }
        super.processTask(task, processor, dataOutPutSource, threadPoolExecutor);
    }

}
